#!/usr/bin/python
#2013 summer iul
from Tkinter import*
root = Tk()
can = Canvas(root,width = 740,height = 780)
can.pack()
str2 = 0
def stan():
	il = 0
	l1 = scl+str2
	while il < 5:
		can.create_line(0,scl*10+l1,740,scl*10+l1)
		l1 = l1 + scl
		il = il + 1
ff = open('in','r')
scl = 10
down = True
down1 = True
char = "C"
i = 0
pos_x = []
pos_x = range(10,740,scl*2)
while True:
	ch = ff.read(1)
	if not ch:
		break
	elif ch == 'C':
		print "C"
		y = scl*15.5+str2
		x = pos_x[i]
		can.create_line(x-scl/2,y+scl/2,x+scl*1.5,y+scl/2)
		i = i + 1
		char1 = char
		char = "C"
		down = False
	elif ch == 'D':
		print "D"
		y = scl*15+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		char = "D"
	elif ch == 'E':
		print "E"
		y = scl*14.5+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		char = "E"
		down = False
	elif ch == 'F':
		print "F"
		y = scl*14+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		char = "F"
		down = False
	elif ch == 'G':
		print "F"
		y = scl*13.5+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		char = "G"
		down = False
	elif ch == 'A':
		print "A"
		y = scl*13+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		char = "A"
		down = False
	elif ch == 'B':
		print "B"
		y = scl*12.5+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		char = "B"
		down = True
	elif ch == 'c':
		print "c"
		y = scl*12+str2
		x = pos_x[i]
		i = i + 1
		char = "c"
		down = True
	elif ch == 'd':
		print "d"
		y = scl*11.5+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		char = "d"
		down1 = down
		down = True
	elif ch == 'e':
		print "e"
		y = scl*11+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		char = "e"
		down = True
	elif ch == 'f':
		print "f"
		y = scl*10.5+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		down = True
	elif ch == 'g':
		print "g"
		y = scl*10+str2
		x = pos_x[i]
		i = i + 1
		char1 = char
		down = True
	elif ch == '(':
		print "("
		y2 = y
		x2 = x
		if char1 == "c" and char == "A":
				down = False
		else:
				down = True
		if down == False:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
		else:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
	elif ch == ')':
		print ")"
		if char == "d" and char1 == "A":
				down = True
		else:
				down = True
		if down1 == False or down == False:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			can.create_line(x2+scl,y2-scl*3,x+scl,y-scl*3,width = 2)
		else:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
			can.create_line(x2,y2+scl*4,x,y+scl*4,width = 2)
	elif ch == '{':
		print "{"
		y2 = y
		x2 = x
		if down == False:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
		else:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
	elif ch == '}':
		print "}"
		if down1 == False or down == False:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			can.create_line(x2+scl,y2-scl*3,x+scl,y-scl*3,width = 2)
			can.create_line(x2+scl,y2-scl*2.5,x+scl,y-scl*2.5,width = 2)
		else:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
			can.create_line(x2,y2+scl*4,x,y+scl*4,width = 2)
			can.create_line(x2,y2+scl*4.5,x,y+scl*4.5,width = 2)
	elif ch == '>':
		print ">"
		if down1 == False or down == False:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			can.create_line(x2+scl,y2-scl*3,x+scl,y-scl*3,width = 2)
			if char == "G" and char1 == "C":
				can.create_line(x2+scl*2,y2-scl*3.4,x+scl,y-scl*2.5,width = 2)
			elif char == "G" and char1 == "A":
				can.create_line(x2+scl*2,y2-scl*2.3,x+scl,y-scl*2.5,width = 2)
				print "OK"
			else:
				can.create_line(x2+scl*2,y2-scl*2.7,x+scl,y-scl*2.5,width = 2)
		else:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
			can.create_line(x2,y2+scl*4,x,y+scl*4,width = 2)
			can.create_line(x2+scl,y2+scl*3.5,x,y+scl*3.5,width = 2)
	elif ch == '<':
		print "<"
		if down1 == False or down == False:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			can.create_line(x2+scl,y2-scl*3,x+scl,y-scl*3,width = 2)
			if char == "G" and char1 == "C":
				can.create_line(x2+scl,y2-scl*2.5,x+scl/5,y-scl*1.7,width = 2)
			elif char == "D" and char1 == "C":
				can.create_line(x2+scl,y2-scl*2.5,x+scl/5,y-scl*2.3,width = 2)
			else:
				can.create_line(x2+scl,y2-scl*2.5,x+scl/5,y-scl*2.3,width = 2)
		else:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
			can.create_line(x2+scl,y2+scl*4,x,y+scl*4,width = 2)
			can.create_line(x2+scl,y2+scl*4.5,x+scl/2,y+scl*4.5,width = 2)
	elif ch == "-":
		print "-"
		if char1 == "B" and char == "A":
			down = True
		elif char1 == "A" and char == "B":
			down = True
		if down == False:
			if char1 == "F": 
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			elif char1 == "G": 
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x+scl,y+scl/2,x+scl,y-scl*2.5)
			elif char == "D": 
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x+scl,y+scl/2,x+scl,y-scl*3.3)
			else:		
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
		else:
			if char == "F": 
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x+scl,y+scl/2,x+scl,y+scl*2.7)
			elif char1 == "A" and char == "B": 
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x,y+scl/2,x,y+scl*4.5)
			elif char == "D": 
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x+scl,y+scl/2,x+scl,y+scl*3.3)
			elif char1 == "d": 
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x,y+scl/2,x,y+scl*4.5)
			elif char1 == "e": 
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x,y+scl/2,x,y+scl*5)
			else:		
				can.create_oval(x,y,x+scl,y+scl,fill = 'black')
				can.create_line(x,y+scl/2,x,y+scl*4)
	elif ch == '1':
		print "1"
		if down == False:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			can.create_line(x+scl,y-scl*3,x+scl+scl/1.5,y-scl*1,x+scl+scl/2.7,y+scl/5,width = 1.5)
		else:
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
			can.create_line(x,y+scl*4,x+scl/1.1,y+scl*2.5,x+scl/1.5,y+scl*1.3,width = 1.5)
	elif ch == '2':
		if down == False:
			print "2"
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			#can.create_oval(x+scl*1.5,y+scl/5.5,x+scl*1.8,y+scl/1.8,fill = 'black')
		else:
			#print "1"
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
			#can.create_oval(x+scl*1.5,y+scl/5.5,x+scl*1.8,y+scl/1.9,fill = 'black')
	elif ch == '3':
		if down == False:
			print "1"
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			can.create_oval(x+scl*1.3,y+scl/5.5,x+scl*1.6,y+scl/1.9,fill = 'black')
		else:
			#print "1"
			can.create_oval(x,y,x+scl,y+scl,fill = 'black')
			can.create_line(x,y+scl/2,x,y+scl*4)
			can.create_oval(x+scl*1.2,y+scl/5.5,x+scl*1.5,y+scl/1.9,fill = 'black')
	elif ch == '4':
		if down == False:
			print "4"
			can.create_oval(x,y,x+scl,y+scl)
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			#can.create_oval(x+scl*1.5,y+scl/5.5,x+scl*1.8,y+scl/1.8,fill = 'black')
		else:
			#print "1"
			can.create_oval(x,y,x+scl,y+scl)
			can.create_line(x,y+scl/2,x,y+scl*4)
			#can.create_oval(x+scl*1.5,y+scl/5.5,x+scl*1.8,y+scl/1.9,fill = 'black')
	elif ch == '6':
		if down == False:
			print "6"
			can.create_oval(x,y,x+scl,y+scl)
			can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			can.create_oval(x+scl*1.5,y+scl/5.5,x+scl*1.8,y+scl/1.8,fill = 'black')
		else:
			#print "1"
			can.create_oval(x,y,x+scl,y+scl)
			can.create_line(x,y+scl/2,x,y+scl*4)
			can.create_oval(x+scl*1.5,y+scl/5.5,x+scl*1.8,y+scl/1.9,fill = 'black')
	elif ch == '8':
		if down == False:
			print "8"
			can.create_oval(x,y,x+scl,y+scl)
			#can.create_line(x+scl,y+scl/2,x+scl,y-scl*3)
			#can.create_oval(x+scl*1.5,y+scl/5.5,x+scl*1.8,y+scl/1.8,fill = 'black')
		else:
			#print "1"
			can.create_oval(x,y,x+scl,y+scl)
			#can.create_line(x,y+scl/2,x,y+scl*4)
			#can.create_oval(x+scl*1.5,y+scl/5.5,x+scl*1.8,y+scl/1.9,fill = 'black')
	elif ch == '|':
		print "|"
		can.create_line(pos_x[i]-scl/2,scl*15+str2,pos_x[i]-scl/2,scl*11+str2,width = 1.5)
	elif ch == 'r':
		print "|"
		can.create_line(pos_x[i]-scl/2,scl*15,pos_x[i]-scl,scl*13,width = 1.5)
	elif ch == 'z':
		print "|"
		can.create_line(pos_x[i]-scl/2,scl*15+str2,pos_x[i]-scl/2,scl*13+str2,width = 1.5)
	elif ch == 'x':
		print "|"
		can.create_line(pos_x[i]-scl/2,scl*15,pos_x[i]+scl,scl*13,width = 1.5)
	elif ch == " ":
		pass
		i = i + 1
	# accords
	elif ch == 'm':
		print "m"
		can.create_text(pos_x[i]+scl,scl*8,text = "moll")
		i = i - 1
	elif ch == 'j':
		print "j"
		can.create_text(pos_x[i]+scl,scl*8,text = "dur")
		i = i - 1
	elif ch == ',':
		print "j"
		can.create_text(pos_x[i]-scl,scl*10,text = "down")
	elif ch == 't':
		print "||"
		can.create_line(pos_x[i]+scl/5,scl*15+str2,pos_x[i]+scl/5,scl*11+str2,width = 5)
	# diez bemol
	elif ch == '_':
		print "_"
		can.create_text(pos_x[i]-scl*2.5,y+scl/1.8,text = "b")
	elif ch == '^':
		print "_"
		can.create_text(pos_x[i]-scl*2.8,y+scl/1.8,text = "#")
	elif ch == '=':
		print "_"
		can.create_text(pos_x[i]-scl*2.8,y+scl/1.8,text = "=")
	elif ch == 'n':
		i = 0
		str2 = scl*10
		stan()
	elif ch == 'v':
		i = 0
		str3 = scl*20
		str2 = str3
		stan()
	elif ch == 's':
		i = 0
		str4 = scl*30
		str2 = str4
		stan()
	else:
		continue
str2 = scl/11
stan()
ff.close()
can.postscript(file = "out.ps",width = '740',height = '780')
root.mainloop()
